package com.example.month11.festivalsms.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.example.month11.festivalsms.bean.SendedMsg;

// 单例的形式，操作数据库
public class SmsDbOpenHelper extends SQLiteOpenHelper {
    public static final String DB_NAME = "sms.db";
    public static final int DB_VERSION = 1;

    // 构造方法
    private SmsDbOpenHelper(Context context) {
        // context.getApplicationContext() 避免造成内存泄漏。
        super(context.getApplicationContext(), DB_NAME, null, DB_VERSION);
    }

    private static SmsDbOpenHelper mInstance;
    public static SmsDbOpenHelper getInstance(Context context) {
        if (mInstance == null) {
            synchronized (SmsDbOpenHelper.class) {
                if (mInstance == null) {
                    mInstance = new SmsDbOpenHelper(context);
                }
            }
        }
        return mInstance;
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        // 数据库建表sql语句
        String sql = "create table " + SendedMsg.TAB_NAME + " ( " +
                " _id integer primary key autoincrement , " +
                SendedMsg.COLUMN_DATE + " integer, " +
                SendedMsg.COLUMN_FESTIVAL_NAME + " text , " +
                SendedMsg.COLUMN_MSG + " text , " +
                SendedMsg.COLUMN_NAMES + " text , " +
                SendedMsg.COLUMN_NUMBERS + " text  " +
                " )";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }


}
